package com.yiwei.hdb.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yiwei.hdb.R;
import com.yiwei.hdb.activity.LookPayProcessActivity;
import com.yiwei.hdb.activity.V2MyQrcodeActivity;
import com.yiwei.hdb.constant.Const;
import com.yiwei.hdb.model.V3HomeIndexModel;
import com.yiwei.hdb.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-6-12.
 */

public class V3HomeBottomTwoFragment extends BaseFragment {
    @BindView(R.id.img_icon)
    ImageView imgIcon;
    Unbinder unbinder;
    private V3HomeIndexModel.DataBean.BannersBean data;

    public void setData(V3HomeIndexModel.DataBean.BannersBean data) {
        this.data = data;
    }


    @Override
    protected int setLayoutId() {
        return R.layout.fragment_v3_home_bottom_two;
    }

    @Override
    protected void initView() {
        if (data != null) {
            Glide.with(getContext()).load(data.image).placeholder(R.color.image_default).into(imgIcon);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.img_icon)
    public void onViewClicked() {
        if (data != null) {
            if (data.open_url_type == 0 && !TextUtils.isEmpty(data.remark)) {
                if (data.remark.equals("invite")) {
                    Util.startActivity(getActivity(), V2MyQrcodeActivity.class);
                }
            } else {
                Intent intent = new Intent(getContext(), LookPayProcessActivity.class);
                intent.putExtra("title", data.title);
                intent.putExtra(Const.KEY.PROCESS_URL, data.url);
//                        intent.putExtra("title", data.getData().get(position).getName());
                startActivity(intent);
            }

        }
    }
}
